<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>pymunk.pygame_util Module &mdash; pymunk 4.0.0 documentation</title>
    
    <link rel="stylesheet" href="_static/pymunk.css" type="text/css" />
    <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    './',
        VERSION:     '4.0.0',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="_static/jquery.js"></script>
    <script type="text/javascript" src="_static/underscore.js"></script>
    <script type="text/javascript" src="_static/doctools.js"></script>
    <link rel="shortcut icon" href="_static/pymunk_favicon.ico"/>
    <link rel="top" title="pymunk 4.0.0 documentation" href="index.html" />
    <link rel="up" title="API Reference" href="pymunk.html" />
    <link rel="next" title="pymunk.pyglet_util Module" href="pymunk.pyglet_util.html" />
    <link rel="prev" title="pymunk.util Module" href="pymunk.util.html" /> 
  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="pymunk.pyglet_util.html" title="pymunk.pyglet_util Module"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="pymunk.util.html" title="pymunk.util Module"
             accesskey="P">previous</a> |</li>
        <li><a href="index.html">pymunk 4.0.0 documentation</a> &raquo;</li>
          <li><a href="pymunk.html" accesskey="U">API Reference</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="pymunk-pygame-util-module">
<h1><a class="reference internal" href="#module-pymunk.pygame_util" title="pymunk.pygame_util"><tt class="xref py py-mod docutils literal"><span class="pre">pymunk.pygame_util</span></tt></a> Module<a class="headerlink" href="#pymunk-pygame-util-module" title="Permalink to this headline">¶</a></h1>
<div class="custom-index container">
<script type="text/javascript" src='_static/pymunk.js'></script></div>
<span class="target" id="module-pymunk.pygame_util"></span><p>This submodule contains helper functions to help with quick prototyping 
using pymunk together with pygame.</p>
<p>Intended to help with debugging and prototyping, not for actual production use
in a full application. The methods contained in this module is opinionated 
about your coordinate system and not in any way optimized.</p>
<dl class="function">
<dt id="pymunk.pygame_util.draw">
<tt class="descclassname">pymunk.pygame_util.</tt><tt class="descname">draw</tt><big>(</big><em>surface</em>, <em>*objs</em><big>)</big><a class="reference internal" href="_modules/pymunk/pygame_util.html#draw"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pymunk.pygame_util.draw" title="Permalink to this definition">¶</a></dt>
<dd><p>Draw one or many pymunk objects on a pygame.Surface object.</p>
<dl class="docutils">
<dt>This method currently supports drawing of</dt>
<dd><ul class="first last simple">
<li>pymunk.Space</li>
<li>pymunk.Segment</li>
<li>pymunk.Circle</li>
<li>pymunk.Poly</li>
<li>pymunk.Constraint objects</li>
</ul>
</dd>
</dl>
<p>If a Space is passed in all shapes in that space will be drawn. 
Unrecognized objects will be ignored (for example if you pass in a 
constraint).</p>
<p>Typical usage:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">pymunk</span><span class="o">.</span><span class="n">pygame_util</span><span class="o">.</span><span class="n">draw</span><span class="p">(</span><span class="n">screen</span><span class="p">,</span> <span class="n">my_space</span><span class="p">)</span>
</pre></div>
</div>
<p>You can control the color of a shape by setting shape.color to the color 
you want it drawn in.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">my_shape</span><span class="o">.</span><span class="n">color</span> <span class="o">=</span> <span class="n">pygame</span><span class="o">.</span><span class="n">color</span><span class="o">.</span><span class="n">THECOLORS</span><span class="p">[</span><span class="s">&quot;pink&quot;</span><span class="p">]</span>
</pre></div>
</div>
<p>If you do not want a shape to be drawn, set shape.ignore_draw to True.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">my_shape</span><span class="o">.</span><span class="n">ignore_draw</span> <span class="o">=</span> <span class="bp">True</span>
</pre></div>
</div>
<p>Not all constraints are currently drawn in a very clear way, but all the 
different shapes should look fine both as static and dynamic objects.</p>
<p>See pygame_util.demo.py for a full example</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters :</th><td class="field-body"><dl class="first last docutils">
<dt>surface <span class="classifier-delimiter">:</span> <span class="classifier">pygame.Surface</span></dt>
<dd><p class="first last">Surface that the objects will be drawn on</p>
</dd>
<dt>objs <span class="classifier-delimiter">:</span> <span class="classifier">One or many objects to draw</span></dt>
<dd><p class="first last">Can be either a single object or a list like container with 
objects.</p>
</dd>
</dl>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="function">
<dt id="pymunk.pygame_util.get_mouse_pos">
<tt class="descclassname">pymunk.pygame_util.</tt><tt class="descname">get_mouse_pos</tt><big>(</big><em>surface</em><big>)</big><a class="reference internal" href="_modules/pymunk/pygame_util.html#get_mouse_pos"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pymunk.pygame_util.get_mouse_pos" title="Permalink to this definition">¶</a></dt>
<dd><p>Get position of the mouse pointer in pymunk coordinates.</p>
</dd></dl>

<dl class="function">
<dt id="pymunk.pygame_util.to_pygame">
<tt class="descclassname">pymunk.pygame_util.</tt><tt class="descname">to_pygame</tt><big>(</big><em>p</em>, <em>surface</em><big>)</big><a class="reference internal" href="_modules/pymunk/pygame_util.html#to_pygame"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pymunk.pygame_util.to_pygame" title="Permalink to this definition">¶</a></dt>
<dd><p>Convenience method to convert pymunk coordinates to pygame surface 
local coordinates</p>
</dd></dl>

<dl class="function">
<dt id="pymunk.pygame_util.from_pygame">
<tt class="descclassname">pymunk.pygame_util.</tt><tt class="descname">from_pygame</tt><big>(</big><em>p</em>, <em>surface</em><big>)</big><a class="reference internal" href="_modules/pymunk/pygame_util.html#from_pygame"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pymunk.pygame_util.from_pygame" title="Permalink to this definition">¶</a></dt>
<dd><p>Convenience method to convert pygame surface local coordinates to 
pymunk coordinates</p>
</dd></dl>

</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
            <p class="logo"><a href="index.html">
              <img class="logo" src="_static/pymunk_logo_sphinx.png" alt="Logo"/>
            </a></p>
<h3><a href="index.html">Table Of Contents</a></h3>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="readme.html">Readme</a></li>
<li class="toctree-l1"><a class="reference internal" href="news.html">News</a></li>
<li class="toctree-l1"><a class="reference internal" href="installation.html">Installation</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="pymunk.html">API Reference</a><ul class="current">
<li class="toctree-l2 current"><a class="reference internal" href="pymunk.html#pymunk-package"><tt class="docutils literal"><span class="pre">pymunk</span></tt> Package</a><ul class="current">
<li class="toctree-l3"><a class="reference internal" href="pymunk.constraint.html"><tt class="docutils literal"><span class="pre">pymunk.constraint</span></tt> Module</a></li>
<li class="toctree-l3"><a class="reference internal" href="pymunk.vec2d.html"><tt class="docutils literal"><span class="pre">pymunk.vec2d</span></tt> Module</a></li>
<li class="toctree-l3"><a class="reference internal" href="pymunk.util.html"><tt class="docutils literal"><span class="pre">pymunk.util</span></tt> Module</a></li>
<li class="toctree-l3 current"><a class="current reference internal" href=""><tt class="docutils literal"><span class="pre">pymunk.pygame_util</span></tt> Module</a></li>
<li class="toctree-l3"><a class="reference internal" href="pymunk.pyglet_util.html"><tt class="docutils literal"><span class="pre">pymunk.pyglet_util</span></tt> Module</a></li>
<li class="toctree-l3"><a class="reference internal" href="pymunkoptions.html"><tt class="docutils literal"><span class="pre">pymunkoptions</span></tt> Module</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="examples.html">Examples</a></li>
<li class="toctree-l1"><a class="reference internal" href="tutorials.html">Tutorials</a></li>
<li class="toctree-l1"><a class="reference internal" href="advanced.html">Advanced</a></li>
<li class="toctree-l1"><a class="reference external" href="http://code.google.com/p/pymunk/issues/list">Issue Tracker</a></li>
<li class="toctree-l1"><a class="reference external" href="http://code.google.com/p/pymunk/source/checkout">Source Repository</a></li>
<li class="toctree-l1"><a class="reference external" href="http://code.google.com/p/pymunk/downloads/list">Downloads</a></li>
<li class="toctree-l1"><a class="reference internal" href="license.html">License</a></li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="pymunk.util.html"
                        title="previous chapter"><tt class="docutils literal"><span class="pre">pymunk.util</span></tt> Module</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="pymunk.pyglet_util.html"
                        title="next chapter"><tt class="docutils literal"><span class="pre">pymunk.pyglet_util</span></tt> Module</a></p>
  <h3>This Page</h3>
  <ul class="this-page-menu">
    <li><a href="_sources/pymunk.pygame_util.txt"
           rel="nofollow">Show Source</a></li>
  </ul>
<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="pymunk.pyglet_util.html" title="pymunk.pyglet_util Module"
             >next</a> |</li>
        <li class="right" >
          <a href="pymunk.util.html" title="pymunk.util Module"
             >previous</a> |</li>
        <li><a href="index.html">pymunk 4.0.0 documentation</a> &raquo;</li>
          <li><a href="pymunk.html" >API Reference</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
        &copy; Copyright 2013, Victor Blomqvist.
      Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.2b1.
    </div>
  </body>
</html>